﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class AdminCMS_tab_Class_Manage : System.Web.UI.Page
{
    #region 成员
    protected string oldpath = string.Empty;        //原始节点
    protected string targetpath = string.Empty;     //目标节点
    #endregion

    #region 方法
    /// <summary>
    /// 检验选择
    /// </summary>    
    bool CheckNode()
    {
        //选中节点
        if (class_old.SelectedIndex == -1 || class_target.SelectedIndex == -1)
        {
            UIMethod.Alert("请先选中一个 [原始节点] 和一个 [目标节点]");
            return false;
        }
        oldpath = class_old.SelectedValue;
        targetpath = class_target.SelectedValue;
        //目标不能为子节点
        if (targetpath.IndexOf(oldpath) != -1) 
        {
            UIMethod.Alert("[目标节点] 不能是 [原始节点] 的子节点");
            return false;
        }
        return true;
    }

    void SubmitOk(int datanum)
    {
        GlocalCache.RemoveApplicationData("ProjectNodes");

        UIMethod.Alert("影响了" + datanum.ToString() + "条");
        UIMethod.GoToURL(Request.Path, false);
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            class_old.Items.AddRange(GlocalCache.GetProjectNodes_ListItems(1));
            class_old.Items.Insert(0, new ListItem("-- 根节点 --", "00"));
            class_target.Items.AddRange(GlocalCache.GetProjectNodes_ListItems(1));
            class_target.Items.Insert(0, new ListItem("-- 根节点 --", "00"));
        }
    }

    protected void btn_cut_Click(object sender, EventArgs e)
    {
        //剪切
        if (CheckNode())
        {
            SubmitOk(DataEntity.tab_Class.Cut(oldpath, targetpath));
        }
    }

    protected void btn_copy_Click(object sender, EventArgs e)
    {
        //复制
        if (CheckNode())
        {            
            SubmitOk(DataEntity.tab_Class.CopyTo(oldpath, targetpath));
        }
    }

    protected void btn_unit_Click(object sender, EventArgs e)
    {
        //合并
        if (CheckNode())
        {            
            SubmitOk(DataEntity.tab_Class.Unite(oldpath, targetpath));
        }
    }
}
